package com.gusha.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.gusha.config.SysOperateLog;
import com.gusha.utils.Constants;
import com.gusha.utils.DateUtils;
import com.gusha.utils.WebValueUtil;

import com.gusha.service.SysLogOperateService;
import com.gusha.model.SysLogOperate;


/**
 * @Created：2018-10-26 15:18:16
 * @Author LightSound的代码生成器
 * @Description:SysLogOperateController控制类
 */
@Controller
@RequestMapping("/gx/sysLogOperate")
public class SysLogOperateController {

    // 注入Service
    @Autowired
    private SysLogOperateService sysLogOperateService;

    // 查询列表
    @RequestMapping("list")
    @SysOperateLog(operate = "查看系统用户操作列表")
    public String list(Model model, HttpServletRequest request) {

        //请求参数
        String pageIndex = WebValueUtil.getWebValue(request, "pageIndex");
        String startTime = request.getParameter("startTime");
        String endTime = request.getParameter("endTime");

        //参数封装
        int pageNo = 0;
        if (StringUtils.isNotBlank(pageIndex)) {
            pageNo = Integer.parseInt(pageIndex);
        }
        SysLogOperate sysLogOperate = new SysLogOperate();
        if (StringUtils.isNotBlank(startTime)) {
        	sysLogOperate.setStartTime(DateUtils.parseDate(startTime));
        }
        if (StringUtils.isNotBlank(endTime)) {
        	sysLogOperate.setEndTime(DateUtils.parseDate(endTime));
        }
        //获取分页数据
        Sort sort = new Sort(Sort.Direction.DESC, "createTime");
        Pageable pageable = PageRequest.of(pageNo, Constants.DEFAULT_PAGESIZE, sort);
        Page<SysLogOperate> page = sysLogOperateService.findAll(pageable, sysLogOperate);

        model.addAttribute("page", page);
        model.addAttribute("startTime", startTime);
        model.addAttribute("endTime", endTime);
        return "/admin/sysLogOperate/list";
    }
}
